package com.exchange.controller;

import com.exchange.entity.pojo.*;
import com.exchange.entity.vo.MyWalletVo;
import com.exchange.entity.vo.PackageVo;
import com.exchange.entity.vo.PackagecVo;
import com.exchange.service.PackageTimeService;
import com.exchange.service.PowerTypeService;
import com.exchange.service.VoltageService;
import com.exchange.service.WalletService;
import com.exchange.until.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 周佳辉
 * @date 2024/4/25
 */
@RestController
@RequestMapping("/jeecg-boot")
@Tag(name = "套餐购买")
public class PackageRecordController {

    @Autowired
    private WalletService walletService;

    @Autowired
    private PowerTypeService powerTypeService;

    @Autowired
    private VoltageService voltageService;

    @Autowired
    private PackageTimeService packageTimeService;

    /**
     *
     * @param token
     * @return
     */
    @GetMapping("/buy")
    @Operation(summary = "判断押金是否购买")
    public Result<String> buy(@RequestHeader String token) {
        return this.walletService.buyPackage(token);
    }

    /**
     * todo 调用支付宝api进行付款（从中拿到值之后返回）
     * @param wallet money字段加token
     * @param token
     * @return
     */
    @PostMapping("/ya")
    @Operation(summary = "押金充值")
    public Result ya(@RequestBody Wallet wallet,
                     @RequestHeader String token){
        System.err.println("wallet = " + wallet);
        this.walletService.ya(wallet,token);
        return new Result(200,"押金充值成功成功",true,null);
    }

    /**
     * 获取token
     * @param token
     * @return
     */
    @PostMapping("/tui")
    @Operation(summary = "押金退费")
    public Result tui(@RequestHeader String token){
        this.walletService.tui(token);
        return new Result(200,"押金退费成功",true,null);
    }


    /**
     * 获取套餐种类
     * @return
     */
    @GetMapping("/powertype")
    @Operation(summary = "获取套餐种类")
    public Result<List<PowerType>> powertype(){
        List<PowerType> list = this.powerTypeService.list();
        return new Result<>(200,"获取成功套餐种类",true,list);
    }

    /**
     * 获取套餐电压种类
     * @return
     */
    @GetMapping("/voltage")
    @Operation(summary = "获取套餐电压种类")
    public Result<List<Voltage>> voltage(){
        List<Voltage> list = this.voltageService.list();
        return new Result<>(200,"获取成功电压种类",true,list);
    }

    /**
     * 获取套餐时长
     * @return
     */
    @GetMapping("/packagetime")
    @Operation(summary = "获取套餐时长")
    public Result<List<PackageTime>> pakagetime(){
        List<PackageTime> list = this.packageTimeService.list();
        return new Result<>(200,"获取成功套餐时长",true,list);
    }

    /**
     *  todo 用户使用的套餐卷 查询用户当前所选套餐可以使用的套餐卷列表
     * @param packageRecord 三个主键的传值 ptid \vid \patid \id当前用户拥有的卡卷
     * @return
     */
    @PostMapping("/jia")
    @Operation(summary = "进行价格的计算")
    public Result<BigDecimal> jia(@RequestBody PackageRecord packageRecord){
        System.err.println("packageRecord = packageRecord = " + packageRecord);
        BigDecimal buyVo = this.walletService.jia(packageRecord);
        return new Result<>(200,"价格计算成功",true,buyVo);
    }

    /**
     * 获取token 进行购买套餐 三个主键的传值 ptid \vid \patid \id是当前用户拥有卡卷的id
     * @param packageRecord
     * @param token
     * @return
     */
    @PostMapping("/buys")
    @Operation(summary = "进行购买套餐")
    public Result buys(@RequestBody PackageRecord packageRecord,
                       @RequestHeader String token){
        System.err.println("packageRecord = " + packageRecord);
        this.walletService.buys(packageRecord,token);
        return new Result(200,"购买成功",true,null);
    }


    /**
     *
     * @param packagecVo 一个主键的传值 ptid 、id
     * @return
     */
    @PostMapping("/xufeijiage")
    @Operation(summary = "进行续费价格计算")
    public Result<BigDecimal> xufeijiage(@RequestBody PackagecVo packagecVo){
        BigDecimal xufei = this.walletService.xufeijiage(packagecVo);
        return new Result<>(200,"续费价格计算成功",true,xufei);
    }

    /**
     *
     * @param packageVo  id \patid \cid
     * @return
     */
    @PostMapping("/xufei")
    @Operation(summary = "进行续费")
    public Result xufei(@RequestBody PackageVo packageVo){
        System.err.println("packageVo = " + packageVo);
        this.walletService.xufei(packageVo);
        return new Result(200,"续费成功",true,null);
    }


    @GetMapping("/myWallet")
    @Operation(summary = "获取用户当前使用的套餐")
    public Result<MyWalletVo> myWallet(@RequestHeader String token){
        return this.walletService.getMyWallet(token);
    }
    @GetMapping("/wallets")
    @Operation(summary = "获取用户是否有套餐")
    public boolean wallets(@RequestHeader String token){
        return this.walletService.findWallets(token);
    }

}
